package com.briup.jz.service.impl;

import com.briup.jz.bean.AccountEmployee;
import com.briup.jz.bean.AccountEmployeeExample;
import com.briup.jz.bean.extend.AccountEmployeeExtend;
import com.briup.jz.dao.AccountEmployeeMapper;
import com.briup.jz.dao.extend.AccountEmployeeExtendMapper;
import com.briup.jz.service.IAccountEmployeeService;
import com.briup.jz.utils.CustomerException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: jz
 * @description: 员工业务实现类
 * @author: catmilko
 * @create: 2020/6/12 15:58
 **/
@Service
public class AccountEmployeeServiceImpl implements IAccountEmployeeService{
    @Resource
    private AccountEmployeeMapper accountEmployeeMapper;
    @Resource
    private AccountEmployeeExtendMapper accountEmployeeExtendMapper;

    @Override
    public List<AccountEmployee> findAll() {
        return accountEmployeeMapper.selectByExample(new AccountEmployeeExample());
    }

    @Override
    public AccountEmployee findById(long id) {
        return accountEmployeeMapper.selectByPrimaryKey(id);
    }

    @Override
    public void saveOrUpdate(AccountEmployee accountEmployee) throws CustomerException {
        if (accountEmployee.getId() == null) {
            accountEmployeeMapper.insert(accountEmployee);
        } else {
            if (accountEmployeeMapper.selectByPrimaryKey(accountEmployee.getId()) == null) {
                throw new CustomerException("修改失败，数据不存在");
            }
            accountEmployeeMapper.updateByPrimaryKey(accountEmployee);
        }
    }

    @Override
    public void deleteById(long id) throws CustomerException {
        if (accountEmployeeMapper.selectByPrimaryKey(id) == null) {
            throw new CustomerException("删除失败，数据不存在");
        }
        accountEmployeeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<AccountEmployeeExtend> findAllWithOrderAndUser() {
        return accountEmployeeExtendMapper.selectAllWithOrderAndUser();
    }
}

